home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / gnulib / dkbtrace / pbmplus / source / pbm / pbmtoasc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-06  |  1.7 KB  |  75 lines

  1. /* pbmtoascii.c - read a portable bitmap and produce ASCII graphics
  2. **
  3. ** Copyright (C) 1988 by Jef Poskanzer.
  4. **
  5. ** Permission to use, copy, modify, and distribute this software and its
  6. ** documentation for any purpose and without fee is hereby granted, provided
  7. ** that the above copyright notice appear in all copies and that both that
  8. ** copyright notice and this permission notice appear in supporting
  9. ** documentation.  This software is provided "as is" without express or
  10. ** implied warranty.
  11. */
  12.  
  13. #include "pbm.h"
  14.  
  15. void
  16. main( argc, argv )
  17. int argc;
  18. char* argv[];
  19.     {
  20.     FILE* ifp;
  21.     bit** bits;
  22.     register bit* bP;
  23.     register bit* b1P;
  24.     int rows, cols, row, lastcol;
  25.     register int col;
  26.  
  27.     pbm_init( &argc, argv );
  28.  
  29.     if ( argc > 2 )
  30.     pm_usage( "[pbmfile]" );
  31.  
  32.     if ( argc == 2 )
  33.     ifp = pm_openr( argv[1] );
  34.     else
  35.     ifp = stdin;
  36.  
  37.     bits = pbm_readpbm( ifp, &cols, &rows );
  38.  
  39.     pm_close( ifp );
  40.     
  41.     /* Write out rows by twos. */
  42.     for ( row = 0; row < rows; row += 2 )
  43.     {
  44.     /* Find end of lines. */
  45.     for ( lastcol = cols-1; lastcol > 0; --lastcol )
  46.         {
  47.         if ( bits[row][lastcol] == PBM_BLACK )
  48.         break;
  49.         if ( row+1 < rows && bits[row+1][lastcol] == PBM_BLACK )
  50.         break;
  51.         }
  52.         for ( col = 0, bP = bits[row], b1P = bits[row+1]; col <= lastcol; ++col, ++bP, ++b1P )
  53.         {
  54.         if ( *bP == PBM_WHITE )
  55.         {
  56.         if ( row+1 >= rows || *b1P == PBM_WHITE )
  57.             putchar( ' ' );
  58.         else
  59.             putchar( 'o' );
  60.         }
  61.         else
  62.         {
  63.         if ( row+1 >= rows || *b1P == PBM_WHITE )
  64.             putchar( '"' );
  65.         else
  66.             putchar( '$' );
  67.         }
  68.         }
  69.     putchar( '\n' );
  70.         }
  71.  
  72.     pm_close (stdout);
  73.     exit( 0 );
  74.     }
  75.